package com.ygqh.baby.service.impl;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.ygqh.baby.ao.DataStatus;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.mapper.YgBalanceExtraRewardMapper;
import com.ygqh.baby.po.YgBalanceExtraReward;
import com.ygqh.baby.po.YgBalanceExtraRewardExample;
import com.ygqh.baby.service.YgBalanceExtraRewardService;

@Service
public class YgBalanceExtraRewardServiceImpl implements YgBalanceExtraRewardService {

	@Autowired
	private YgBalanceExtraRewardMapper ygBalanceExtraRewardMapper;

	@Override
	public List<YgBalanceExtraReward> find() {
		YgBalanceExtraRewardExample example = new YgBalanceExtraRewardExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygBalanceExtraRewardMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgBalanceExtraRewardExample example = new YgBalanceExtraRewardExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygBalanceExtraRewardMapper.countByExample(example);
	}

	@Override
	public YgBalanceExtraReward findById(Long id) {
		return ygBalanceExtraRewardMapper.selectByPrimaryKey(id);
	}

	@Override
	public int save(YgBalanceExtraReward ygBalanceExtraReward) {
		return ygBalanceExtraRewardMapper.insertSelective(ygBalanceExtraReward);
	}

	@Override
	public int update(YgBalanceExtraReward ygBalanceExtraReward) {
		return ygBalanceExtraRewardMapper.updateByPrimaryKeySelective(ygBalanceExtraReward);
	}

	@Override
	public ResultSet<YgBalanceExtraReward> search(QueryInfo queryInfo, String q) {
		List<YgBalanceExtraReward> list = ygBalanceExtraRewardMapper.selectSuper(queryInfo, q);
		int count = ygBalanceExtraRewardMapper.countSuper(q);
		ResultSet<YgBalanceExtraReward> resultSet = new ResultSet<YgBalanceExtraReward>(count, list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		YgBalanceExtraRewardExample example = new YgBalanceExtraRewardExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		YgBalanceExtraReward record = new YgBalanceExtraReward();
		record.setStatus(DataStatus.Delete);

		return ygBalanceExtraRewardMapper.updateByExampleSelective(record, example);
	}

	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[] { id });
	}

	@Override
	public int saveOrUpdate(YgBalanceExtraReward ygBalanceExtraReward) {
		int r = 0;
		if (ygBalanceExtraReward.getId() != null) {
			r = this.update(ygBalanceExtraReward);
		} else {
			r = this.save(ygBalanceExtraReward);
		}
		return r;
	}

	@Override
	public int addBatch(List<YgBalanceExtraReward> result) {
		if(CollectionUtils.isEmpty(result)){
			return 0;
		}
		return ygBalanceExtraRewardMapper.addBatch(result);
	}

}
